package com.sansui.blog.controller.admin;

import com.sansui.blog.pojo.ResponseResult;
import com.sansui.blog.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @name: IndexController
 * @author: Sansui
 * @Software: IDEA
 * @Blog: https://www.cnblogs.com/sansui6/
 * @date: 2022-03-21 20:48
 **/

//后台首页控制器

@Controller
@RequestMapping("/admin")
public class AdminIndexController {

    //后台首页
    @GetMapping("/index")
    public String index() {
        return "admin/index";
    }


    // 后台首页获取用户信息

    @PostMapping("/index")
    @ResponseBody
    public Map<String, Object> getUserInfo(HttpSession session){
//        User user = (User) session.getAttribute("user");
        Map<String,Object> map = (Map<String, Object>) session.getAttribute("user");
        Map<String,Object> data = new HashMap<>(16);
        data.put("code","200");
//        data.put("data",user.getUsername());
        data.put("data",map.get("nickname"));
        return data;
    }

}
